import java.util.*;


/**
 * @program: data_structures_algorithms
 * @description: 数组+1
 * @author: lld
 * @create: 2021-03-30 19:55
 **/
public class Demo1 {
    public static void main(String[] args) {

        int[] digits={1,2,9};
        int[] ints = new Demo1().plusOne(digits);
        System.out.println(Arrays.toString(ints));
    }
    public int[] plusOne(int[] digits) {
        int len = digits.length;
        for(int i = len - 1; i >= 0; i--) {
            digits[i]++;
            digits[i] %= 10;
            if(digits[i]!=0)
                return digits;
        }
        digits = new int[len + 1];
        digits[0] = 1;
        return digits;
    }
}
